/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package alcatelparser.modules;

import alcatelparser.modules.io.FileWriter;
import alcatelparser.tags.ITagParser;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 *
 * @author geniuz
 */
public class FullFormBuilder
    implements IOutBuilder
{

    public FullFormBuilder()
    {
        _currentRecord = "";
    }

    public final void buildHeader(int ai[], int i, int j)
    {
        /*
        String s = (new StringBuilder()).append(OutHelper.getRecordNumber(_fos.getRecordNumber())).append(I.I(8661)).toString();
        s = (new StringBuilder()).append(s).append((new DumpBuilder()).buildDump(i, j, ai)).toString();
        String s1 = (new StringBuilder()).append(s).append(_currentRecord).toString();
        try
        {
            _fos.write(s1);
        }
        catch(Exception ioexception)
        {
           // LOG.error(ioexception);
        }
        _currentRecord = "";
         * */
    }

    public final void writeTagContent(int i, int j, String s, String s1)
    {
        /*
        //Thread.currentThread().sleep(1000);
        StringBuilder tralala = new StringBuilder();
        tralala.append(getSpace(i));
        tralala.append(s);
        tralala.append(getSpaceTillValue(i, j, s));
        tralala.append(s1);
        tralala.append(I.I(4062));
        String str = tralala.toString();
        //System.out.print(str+"\n");
        if(_fos != null)
        {
            try
            {
                _fos.write(str);
            }
            catch(Exception ioexception)
            {
                //LOG.error(ioexception);
            }
        }
        //tralala.append();
        //toString();
        //_currentRecord;
         * */
    }

    public final void writeSummary(int i)
    {
        /*
        if(_fos != null)
        {
            String s = OutHelper.getFooter(_fos.getWroteRecordsNumber(), i, 0, 0);
            try
            {
                _fos.writeSummary(s);
            }
            catch(Exception ioexception)
            {
                //LOG.error(ioexception);
            }
        }
         * */
    }

    public final void writeOverAllHeader(String outfilepath)
    {
        try {
            _fos = new FileWriter(outfilepath);
            } catch (FileNotFoundException ex) {
            //Logger.getLogger(FullFormBuilder.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private String getSpaceTillValue(int i, int j, String s)
    {
        if(s == null)
            s = "";
        if(j == 1)
            i = 0;
        byte byte0 = ((byte)(j != 2 ? 34 : 43));
        int k = byte0 - i - s.length();
        return getSpace(k);
    }

    private String getSpace(int i)
    {
        String s = "";
        for(int j = 0; j < i; j++)
            s = (new StringBuilder()).append(s).append(I.I(4987)).toString();

        return s;
    }

    public final void tagParseEnd(ITagParser itagparser)
    {
    }

    public final void releaseContent()
    {
        if(_fos != null)
            try
            {
                _fos.close();
            }
            catch(Exception ioexception)
            {
                //LOG.error(ioexception);
            }
    }

    public final long getWroteSize()
    {
        if(_fos == null)
            return 0L;
        else
            return _fos.getWroteSize();
    }

    public final int getRecordWroteAmount()
    {
        if(_fos == null)
            return 0;
        else
            return _fos.getWroteRecordsNumber();
    }

    public final void notifyRecordEnd()
    {
        try {
            _fos.notifyRecordEnd();
        } catch (FileNotFoundException ex) {
            //Logger.getLogger(FullFormBuilder.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            //Logger.getLogger(FullFormBuilder.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public final void notifyHeaderEnd(int i, int j, int ai[])
    {
        if(Env.getEnv().isPrintHeader())
            try
            {
                _fos.writeOverallHeader((new StringBuilder()).append(I.I(4124)).append((new DumpBuilder()).buildDump(i, j, ai)).append(_currentRecord).toString());
                _currentRecord = "";
            }
            catch(Exception ioexception)
            {
                //LOG.error(ioexception);
            }
    }

    private FileWriter _fos;
    private static final int CONTENT_START_ANCHOR = 34;
    private static final int DETAILS_START_ANCHOR = 43;
    private String _currentRecord;
    //private static final Logger LOG = Logger.getLogger(com/alcatel/algo/out/FullFormBuilder);

}
